package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Follow;
import cn.wolfcode.trip.base.mapper.FollowMapper;
import cn.wolfcode.trip.base.service.IFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：关注控制器
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: wjh
 * @date: 2019/05/30 13:00
 * 总结:
 */
@Service
public class FollowServiceImpl implements IFollowService {

    @Autowired
    private FollowMapper FollowMapper;

    @Override
    public void addFollow(Follow follow) {
        if (follow.getFansId() == null) {
            throw new RuntimeException("请先登录");
        }
        if(follow.getFansId() == follow.getUserId()){
            throw new RuntimeException("不能关注自己");
        }
        FollowMapper.insert(follow);
    }

    @Override
    public void cancelFollow(Follow follow) {
        if (follow.getFansId() == null) {
            throw new RuntimeException("请先登录");
        }
        FollowMapper.deleteByPrimaryKey(follow);
    }

    @Override
    public Integer listByFansId(Long fansId) {
        return FollowMapper.selectByFansId(fansId);
    }

    @Override
    public Integer listByFollowId(Long userId) {
        return FollowMapper.selectByFollowId(userId);
    }

    @Override
    public Follow listRelations(Follow follow) {
        if (follow.getFansId() == null) {
            throw new RuntimeException("请先登录");
        }
        return FollowMapper.relation(follow);
    }
}
